﻿/////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2008 by Jamesvon, Inc.
// All Rights Reserved.
//
// 文件名：         VonFunctions.cs
// 创建人：         James von
// 创建日期：       2012-4-1 8:00:00
// 文件功能描述：   通用集合结构
//
// 慎重声明：
//
// 本软件包含版权资料、商业秘密以及其他财产资料。用户不可，也不能试图对本软件
// 进行修改、反向工程改造、拆解或反编译，也不能抽取或盗取本软件的组成部分用于
// 生成派生产品或其它产品。
// James von 的名字和代表其软件产品的标记、图案等，不能以任何理由、任何方式
// 用于推广基于本软件之上开发的其它产品。
// James von 保留本软件的所有权利、资格、利益以及此处所涉及到的所有知识产权。
// James von 的所有软件和产品的组成部分均受版权法和国际版权公约保护。除了单
// 用户许可证规定的权限以外，用户不能以任何理由任何方式复制或使用James von的
// 程序、代码、组件、图像、影像剪辑、声音样本以及文本。除了明确的书面授权外，
// James von保留所有的权利。
//
//修订历史记录：
//
//
/////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Von.Library
{
    /// <summary>
    /// 键值对
    /// </summary>
    public class KeyValue
    {
        /// <summary>
        /// 键名称
        /// </summary>
        public string Key;
        /// <summary>
        /// 键内容
        /// </summary>
        public string Value;
        public KeyValue() { }
        public KeyValue(string key, string value)
        {
            this.Key = key;
            this.Value = value;
        }
    }
    /// <summary>
    /// 键值对象
    /// </summary>
    public class KeyObject
    {
        /// <summary>
        /// 键名称
        /// </summary>
        public string Key;
        /// <summary>
        /// 键值对象内容
        /// </summary>
        public object Obj;
        public KeyObject() { }
        public KeyObject(string key, object obj)
        {
            this.Key = key;
            this.Obj = obj;
        }
    }
    /// <summary>
    /// 键值对象
    /// </summary>
    public class KeyValueObject : KeyValue
    {
        /// <summary>
        /// 键值对象内容
        /// </summary>
        public object Obj;
        public KeyValueObject() { }
        public KeyValueObject(string key, string value, object obj)
        {
            this.Key = key;
            this.Value = value;
            this.Obj = obj;
        }
    }
    /// <summary>
    /// 键值集合
    /// </summary>
    public class KeyValueCollection : List<KeyValue>
    {
        /// <summary>
        /// 添加一对键值
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <returns>追加到的位置</returns>
        public void AddData(string key, string value)
        {
            foreach (KeyValue val in this)
            {
                if (val.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    val.Value = value;
                }
            }
            Add(new KeyValue(key, value));
        }
        /// <summary>
        /// 插入一对键值
        /// </summary>
        /// <param name="index">插入位置</param>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <returns>插入位置</returns>
        public int InsertData(int index, string key, string value)
        {
            this.Insert(index, new KeyValue(key, value));
            return index;
        }
        /// <summary>
        /// 删除一对键值
        /// </summary>
        /// <param name="key">键</param>
        public void DeleteKey(string key)
        {
            foreach (KeyValue val in this)
            {
                if (val.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    this.Remove(val);
                    return;
                }
            }
        }
        /// <summary>
        /// 得到某一位置的键值
        /// </summary>
        /// <param name="index">序列位置</param>
        /// <returns>键值</returns>
        public string Keys(int index)
        {
            if (index < 0 || index >= this.Count) return "";
            return this[index].Key;
        }
        /// <summary>
        /// 得到某一位置键内容
        /// </summary>
        /// <param name="index">序列位置</param>
        /// <returns>键内容</returns>
        public string Values(int index)
        {
            if (index < 0 || index >= this.Count) return "";
            return this[index].Value;
        }
        /// <summary>
        /// 按照键值得到键内容
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>键内容</returns>
        public string Values(string key)
        {
            foreach (KeyValue val in this)
            {
                if (val.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    return val.Value;
                }
            }
            return "";
        }
        /// <summary>
        /// 得到设置的值内容
        /// </summary>
        /// <param name="key"键名称</param>
        /// <returns>值内容</returns>
        public string this[string key]
        {
            get
            {
                return Values(key);
            }
            set
            {
                AddData(key, value);
            }
        }
        /// <summary>
        /// 将集合转换为数组输出，例如：["A=123", "B=234"]
        /// </summary>
        /// <returns></returns>
        public string[] ToArray(string splitStr = "=")
        {
            string[] result = new string[Count];
            int i = 0;
            foreach (KeyValue val in this)
            {
                result[i++] = val.Key + splitStr + val.Value;
            }
            return result;
        }
        public string Join(string splitStr = "=", string rowStr = "\r")
        {
            string Result = "";
            foreach (KeyValue val in this)
            {
                Result += (Result == "" ? "" : rowStr) + val.Key + splitStr + val.Value;
            }
            return Result;
        }
        /// <summary>
        /// 加载一个以分隔符分割形成的数组，例如：["A=123", "B=234"]
        /// </summary>
        /// <param name="data"></param>
        /// <param name="splitStr"></param>
        public void LoadFromArray(string[] data, string splitStr = "=")
        {
            foreach (string s in data)
            {
                string[] k_v = s.Split(splitStr);
                Add(new KeyValue(k_v[0], k_v[1]));
            }
        }
        public string Text
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                foreach (KeyValue val in this)
                {
                    sb.AppendLine(val.Key + '=' + val.Value);
                }
                return sb.ToString();
            }
            set
            {
                System.IO.StringReader read = new System.IO.StringReader(value);
                string s = string.Empty;
                while ((s = read.ReadLine()) != null)
                {
                    int idx = s.IndexOf('=');
                    this.Add(new KeyValue(s.Substring(0, idx), s.Substring(idx + 1)));
                }
            }
        }
    }
    /// <summary>
    /// 键值对象集合
    /// </summary>
    public class KeyObjectCollection : List<KeyObject>
    {
        /// <summary>
        /// 键值索引
        /// </summary>
        /// <param name="key">键名称</param>
        /// <returns>键索引</returns>
        public object this[string key]
        {
            get
            {
                KeyObject item = base.Find(i => i.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
                if (item == null) return null;
                return item.Obj;
            }
            set
            {
                KeyObject item = base.Find(i => i.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
                if (item == null) Add(new KeyObject() { Key = key, Obj = value });
                item.Obj = value;
            }
        }
        /// <summary>
        /// 键值索引
        /// </summary>
        /// <param name="index">序号</param>
        /// <returns>键索引</returns>
        public new object this[int index]
        {
            get
            {
                return base[index].Obj;
            }
            set
            {
                base[index].Obj = value;
            }
        }
        /// <summary>
        /// 添加一对键值对象
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="obj">对象</param>
        /// <returns></returns>
        public int AddData(string key, object obj)
        {
            KeyObject item = base.Find(i => i.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
            if (item == null) Add(new KeyObject() { Key = key, Obj = obj });
            else item.Obj = obj;
            return this.Count - 1;
        }
        /// <summary>
        /// 插入一对键值
        /// </summary>
        /// <param name="index">插入位置</param>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="obj">对象</param>
        /// <returns></returns>
        public int InsertData(int index, string key, object obj)
        {
            this.Insert(index, new KeyObject(key, obj));
            return index;
        }
        /// <summary>
        /// 删除一对键值
        /// </summary>
        /// <param name="key">键</param>
        public void DeleteKey(string key)
        {
            foreach (KeyObject val in this)
            {
                if (val.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    this.Remove(val);
                    return;
                }
            }
        }
        /// <summary>
        /// 得到某一位置的键值
        /// </summary>
        /// <param name="index">序列位置</param>
        /// <returns>键值</returns>
        public string Keys(int index)
        {
            if (index < 0 || index >= this.Count) return "";
            return base[index].Key;
        }
        /// <summary>
        /// 得到某一位置键对象
        /// </summary>
        /// <param name="index">序列位置</param>
        /// <returns>键内容</returns>
        public object Objects(int index)
        {
            if (index < 0 || index >= this.Count) return "";
            return base[index].Obj;
        }
        /// <summary>
        /// 按照键值得到键对象
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>键内容</returns>
        public object Objects(string key)
        {
            foreach (KeyObject val in this)
            {
                if (val.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    return val.Obj;
                }
            }
            return null;
        }
        /// <summary>
        /// 集合文本方案缓存
        /// </summary>
        public string Text
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                foreach (KeyObject val in this)
                {
                    sb.AppendLine(val.Key + '=' + val.Obj.ToString());
                }
                return sb.ToString();
            }
            set
            {
                System.IO.StringReader read = new System.IO.StringReader(value);
                string s = string.Empty;
                while ((s = read.ReadLine()) != null)
                {
                    int idx = s.IndexOf('=');
                    this.Add(new KeyObject(s.Substring(0, idx - 1), s.Substring(idx + 1)));
                }
            }
        }
    }
    /// <summary>
    /// 键值对象集合
    /// </summary>
    public class KeyValueObjectCollection : List<KeyValueObject>
    {
        /// <summary>
        /// 键值索引
        /// </summary>
        /// <param name="key">键名称</param>
        /// <returns>键索引</returns>
        public KeyValueObject this[string key]
        {
            get
            {
                //return this.Find(v => v.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
                foreach (KeyValueObject obj in this)
                {
                    if (obj.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                        return obj;
                }
                return null;
            }
        }
        /// <summary>
        /// 添加一对键值对象
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="obj">对象</param>
        /// <returns></returns>
        public int AddData(string key, string value, object obj)
        {
            KeyValueObject o = this[key];
            if (o != null) return 0;
            this.Add(new KeyValueObject(key, value, obj));
            return this.Count - 1;
        }
        /// <summary>
        /// 插入一对键值
        /// </summary>
        /// <param name="index">插入位置</param>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="obj">对象</param>
        /// <returns></returns>
        public int InsertData(int index, string key, string value, object obj)
        {
            this.Insert(index, new KeyValueObject(key, value, obj));
            return index;
        }
        /// <summary>
        /// 删除一对键值
        /// </summary>
        /// <param name="key">键</param>
        public void DeleteKey(string key)
        {
            foreach (KeyValueObject val in this)
            {
                if (val.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    this.Remove(val);
                    return;
                }
            }
        }
        /// <summary>
        /// 得到某一位置的键值
        /// </summary>
        /// <param name="index">序列位置</param>
        /// <returns>键值</returns>
        public string Keys(int index)
        {
            if (index < 0 || index >= this.Count) return "";
            return this[index].Key;
        }
        /// <summary>
        /// 得到某一位置键内容
        /// </summary>
        /// <param name="index">序列位置</param>
        /// <returns>键内容</returns>
        public string Values(int index)
        {
            if (index < 0 || index >= this.Count) return "";
            return this[index].Value;
        }
        /// <summary>
        /// 得到某一位置键对象
        /// </summary>
        /// <param name="index">序列位置</param>
        /// <returns>键内容</returns>
        public object Objects(int index)
        {
            if (index < 0 || index >= this.Count) return "";
            return this[index].Obj;
        }
        /// <summary>
        /// 按照键值得到键内容
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>键内容</returns>
        public string Values(string key)
        {
            foreach (KeyValueObject val in this)
            {
                if (val.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    return val.Value;
                }
            }
            return "";
        }
        /// <summary>
        /// 按照键值得到键对象
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>键内容</returns>
        public object Objects(string key)
        {
            foreach (KeyValueObject val in this)
            {
                if (val.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    return val.Obj;
                }
            }
            return null;
        }
        /// <summary>
        /// 集合文本方案缓存
        /// </summary>
        public string Text
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                foreach (KeyValueObject val in this)
                {
                    sb.AppendLine(val.Key + '=' + val.Value);
                }
                return sb.ToString();
            }
            set
            {
                System.IO.StringReader read = new System.IO.StringReader(value);
                string s = string.Empty;
                while ((s = read.ReadLine()) != null)
                {
                    int idx = s.IndexOf('=');
                    this.Add(new KeyValueObject(s.Substring(0, idx - 1), s.Substring(idx + 1), null));
                }
            }
        }
    }
    public class DBParam
    {
        public string key { get; set; }
        public SqlDbType dbType { get; set; }
        public object data { get; set; }
        public DBParam(string key, SqlDbType dbType, object data)
        {
            this.key = key;
            this.dbType = dbType;
            this.data = data;
        }
    }
    public class DBParamCollection : List<DBParam>
    {
        /// <summary>
        /// 键值索引
        /// </summary>
        /// <param name="key">键名称</param>
        /// <returns>键索引</returns>
        public DBParam this[string key]
        {
            get
            {
                foreach (DBParam obj in this)
                {
                    if (obj.key.Equals(key, StringComparison.OrdinalIgnoreCase))
                        return obj;
                }
                return null;
            }
        }
        /// <summary>
        /// 添加一对键值对象
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="obj">对象</param>
        /// <returns></returns>
        public int AddData(string key, SqlDbType dbType, object data)
        {
            DBParam o = this[key];
            if (o != null) return 0;
            this.Add(new DBParam(key, dbType, data));
            return this.Count - 1;
        }
        /// <summary>
        /// 插入一对键值
        /// </summary>
        /// <param name="index">插入位置</param>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="obj">对象</param>
        /// <returns></returns>
        public int InsertData(int index, string key, SqlDbType dbType, object data)
        {
            this.Insert(index, new DBParam(key, dbType, data));
            return index;
        }
        /// <summary>
        /// 删除一对键值
        /// </summary>
        /// <param name="key">键</param>
        public void DeleteKey(string key)
        {
            foreach (DBParam val in this)
            {
                if (val.key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    this.Remove(val);
                    return;
                }
            }
        }
        /// <summary>
        /// 得到某一位置的键值
        /// </summary>
        /// <param name="index">序列位置</param>
        /// <returns>键值</returns>
        public string Keys(int index)
        {
            if (index < 0 || index >= this.Count) return "";
            return this[index].key;
        }
        /// <summary>
        /// 得到某一位置键内容
        /// </summary>
        /// <param name="index">序列位置</param>
        /// <returns>键内容</returns>
        public SqlDbType DBType(int index)
        {
            if (index < 0 || index >= this.Count) return SqlDbType.Int;
            return this[index].dbType;
        }
        /// <summary>
        /// 得到某一位置键对象
        /// </summary>
        /// <param name="index">序列位置</param>
        /// <returns>键内容</returns>
        public object Objects(int index)
        {
            if (index < 0 || index >= this.Count) return "";
            return this[index].data;
        }
        /// <summary>
        /// 按照键值得到键内容
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>键内容</returns>
        public SqlDbType DBTypes(string key)
        {
            foreach (DBParam val in this)
            {
                if (val.key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    return val.dbType;
                }
            }
            return SqlDbType.Int;
        }
        /// <summary>
        /// 按照键值得到键对象
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>键内容</returns>
        public object Objects(string key)
        {
            foreach (DBParam val in this)
            {
                if (val.key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    return val.data;
                }
            }
            return null;
        }
    }
    public class VonJsonTable
    {
        public List<string> ColumnCaptions = new List<string>();
        public List<string> ColumnNames = new List<string>();
        private List<List<string>> Cells = new List<List<string>>();
        public string this[int col, int row]
        {
            get
            {
                return Cells[row][col];
            }
            set
            {
            }
        }
    }

    /// <summary>
    /// 键值对,{key}={value}+{data},{object}={object}+object
    /// </summary>
    public class VonObjectItem
    {
        /// <summary>
        /// 主键值
        /// </summary>
        public object Key { get; set; }
        /// <summary>
        /// 值
        /// </summary>
        public object Value { get; set; }
        /// <summary>
        /// 对象
        /// </summary>
        public object Data { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public VonObjectItem()
        {
        }
        /// <summary>
        /// 带赋值的构造函数
        /// </summary>
        /// <param name="key">主键</param>
        /// <param name="value">值</param>
        public VonObjectItem(object key, object value, object data)
        {
            this.Key = key;
            this.Value = value;
            this.Data = data;
        }
    }
    /// <summary>
    /// 键值对,{key}={value},{string}={string}
    /// </summary>
    public class VonKeyValueItem
    {
        /// <summary>
        /// 主键值
        /// </summary>
        public string Key
        {
            get { return _Key; }
            set { _Key = value; }
        }
        private string _Key;

        /// <summary>
        /// 值
        /// </summary>
        public string Value
        {
            get { return _Value; }
            set { _Value = value; }
        }
        private string _Value;

        /// <summary>
        /// 构造函数
        /// </summary>
        public VonKeyValueItem()
        {
        }
        /// <summary>
        /// 带赋值的构造函数
        /// </summary>
        /// <param name="key">主键</param>
        /// <param name="value">值</param>
        public VonKeyValueItem(string key, string value)
        {
            this.Key = key;
            this.Value = value;
        }
    }
    /// <summary>
    /// 键值单元,{key}={value}+{data},{string}={string}+{object}
    /// </summary>
    public class VonDataItem : VonKeyValueItem
    {
        /// <summary>
        /// 值
        /// </summary>
        public object Data
        {
            get { return _Data; }
            set { _Data = value; }
        }
        private object _Data;

        /// <summary>
        /// 无参的构造函数
        /// </summary>
        public VonDataItem()
        {
            this.Key = "";
            this.Value = "";
            this.Data = null;
        }
        /// <summary>
        /// 带赋值的构造函数
        /// </summary>
        /// <param name="key">主键</param>
        /// <param name="value">值</param>
        /// <param name="data">对象</param>
        public VonDataItem(string key, string value, object data)
        {
            this.Key = key;
            this.Value = value;
            this.Data = data;
        }
    }
    /// <summary>
    /// 链接单元，{key}={value}+{data}+{Prevous}+{Next}，{string}={string}+{object}+{linker}+{linker}
    /// </summary>
    public class VonLinkerItem
    {
        /// <summary>
        /// 值
        /// </summary>
        public VonDataItem Data
        {
            get { return _Data; }
            set { _Data = value; }
        }
        private VonDataItem _Data = null;

        /// <summary>
        /// 前一个值
        /// </summary>
        public VonLinkerItem Prevous
        {
            get { return _Prevous; }
            set { _Prevous = value; }
        }
        private VonLinkerItem _Prevous = null;

        /// <summary>
        /// 后一个值
        /// </summary>
        public VonLinkerItem Next
        {
            get { return _Next; }
            set { _Next = value; }
        }
        private VonLinkerItem _Next = null;
    }
    /// <summary>
    /// 链表结构
    /// </summary>
    public class VonLinkerCollection
    {
        private VonLinkerItem currentItem = new VonLinkerItem();
        private VonLinkerItem first = null;
        private VonLinkerItem laster = null;
        #region Location and moving functions
        /// <summary>
        /// 回到头
        /// </summary>
        public VonLinkerItem First()
        {
            currentItem = first;
            return currentItem;
        }
        /// <summary>
        /// 移到最后一个节点上
        /// </summary>
        public VonLinkerItem Laster()
        {
            currentItem = laster;
            return currentItem;
        }
        /// <summary>
        /// 向后移动一个节点
        /// </summary>
        /// <returns></returns>
        public bool Next()
        {
            if (!EOF)
            {
                currentItem = currentItem.Next;
                return true;
            }
            return false;
        }
        /// <summary>
        /// 向前移动一个节点
        /// </summary>
        /// <returns></returns>
        public bool Prevous()
        {
            if (!BOF)
            {
                currentItem = currentItem.Prevous;
                return true;
            }
            return false;
        }
        /// <summary>
        /// 将当前节点向后移动一个节点
        /// </summary>
        public void MoveToNext()
        {
            if (currentItem.Data == null) return;
            if (currentItem.Next == null) return;
            VonDataItem data = currentItem.Data;
            currentItem.Data = currentItem.Next.Data;
            currentItem.Next.Data = data;
        }
        /// <summary>
        /// 将当前节点向前移动一个节点
        /// </summary>
        public void MoveToPrevous()
        {
            if (currentItem.Data == null) return;
            if (currentItem.Prevous == null) return;
            VonDataItem data = currentItem.Data;
            currentItem.Data = currentItem.Prevous.Data;
            currentItem.Prevous.Data = data;
        }
        /// <summary>
        /// 将当前节点移动到头
        /// </summary>
        public void MoveToFirst()
        {
            if (currentItem.Data == null) return;
            while (currentItem.Prevous != null)
            {
                VonDataItem data = currentItem.Data;
                currentItem.Data = currentItem.Prevous.Data;
                currentItem.Prevous.Data = data;
                currentItem = currentItem.Prevous;
            }
        }
        /// <summary>
        /// 将当前节点移动到尾
        /// </summary>
        public void MoveToLaster()
        {
            if (currentItem.Data == null) return;
            while (currentItem.Next != null)
            {
                VonDataItem data = currentItem.Data;
                currentItem.Data = currentItem.Next.Data;
                currentItem.Next.Data = data;
                currentItem = currentItem.Next;
            }
        }
        /// <summary>
        /// 根据键名进行定位
        /// </summary>
        /// <param name="Key">键名</param>
        /// <param name="fromFirst">是否从头开始</param>
        /// <returns>定位是否成功</returns>
        public bool LocateByKey(string Key, bool fromFirst)
        {
            if (currentItem.Data == null) return false;
            if (fromFirst) currentItem = first;
            do
            {
                if (Key.Equals(currentItem.Data.Key, StringComparison.OrdinalIgnoreCase))
                    return true;
            } while (Next());
            return false;
        }
        /// <summary>
        /// 根据键名进行定位
        /// </summary>
        /// <param name="Key">键名</param>
        /// <returns>定位是否成功</returns>
        public bool LocateByKey(string Key) { return LocateByKey(Key, true); }
        /// <summary>
        /// 根据键值进行定位
        /// </summary>
        /// <param name="Value">键值</param>
        /// <param name="fromFirst">是否从头开始</param>
        /// <returns>定位是否成功</returns>
        public bool LocateByValue(string Value, bool fromFirst)
        {
            if (currentItem.Data == null) return false;
            if (fromFirst) currentItem = first;
            do
            {
                if (Value.Equals(currentItem.Data.Value, StringComparison.OrdinalIgnoreCase))
                    return true;
            } while (Next());
            return false;
        }
        /// <summary>
        /// 根据键值从头开始进行定位
        /// </summary>
        /// <param name="Value">键值</param>
        /// <param name="fromFirst">是否</param>
        /// <returns>定位是否成功</returns>
        public bool LocateByValue(string Value) { return LocateByValue(Value, true); }
        /// <summary>
        /// 根据对象进行定位
        /// </summary>
        /// <param name="Data">对象</param>
        /// <param name="fromFirst">是否从头开始</param>
        /// <returns>定位是否成功</returns>
        public bool LocateByData(object Data, bool fromFirst)
        {
            if (currentItem.Data == null) return false;
            if (fromFirst) currentItem = first;
            do
            {
                if (Data.Equals(currentItem.Data.Data))
                    return true;
            } while (Next());
            return false;
        }
        /// <summary>
        /// 根据对象从头开始进行定位
        /// </summary>
        /// <param name="Data">对象</param>
        /// <param name="fromFirst">是否</param>
        /// <returns>定位是否成功</returns>
        public bool LocateByData(object Data) { return LocateByData(Data, true); }
        #endregion
        #region Properties
        /// <summary>
        /// 数据数量
        /// </summary>
        public int Count
        {
            get { return _Count; }
        }
        private int _Count = 0;
        /// <summary>
        /// 是否处于链表头
        /// </summary>
        public bool BOF
        {
            get
            {
                if (currentItem.Prevous == null) return true;
                return false;
            }
        }
        /// <summary>
        /// 是否处于结尾位置
        /// </summary>
        public bool EOF
        {
            get
            {
                if (currentItem.Next == null) return true;
                return false;
            }
        }
        /// <summary>
        /// 得到当前节点
        /// </summary>
        public VonLinkerItem Current
        {
            get { return currentItem; }
        }
        /// <summary>
        /// 得到当前节点的键值
        /// </summary>
        public string CurrentKey
        {
            get
            {
                if (currentItem.Data == null) return "";
                return currentItem.Data.Key;
            }
        }
        /// <summary>
        /// 得到当前节点的值
        /// </summary>
        public string CurrentValue
        {
            get
            {
                if (currentItem.Data == null) return "";
                return currentItem.Data.Value;
            }
        }
        /// <summary>
        /// 得到当前节点的对象
        /// </summary>
        public object CurrentData
        {
            get
            {
                if (currentItem.Data == null) return "";
                return currentItem.Data.Data;
            }
        }
        #endregion
        #region Addition or deletion functions
        /// <summary>
        /// 在当前节点后追加一个链接
        /// </summary>
        /// <param name="Key">键名</param>
        /// <param name="Value">键值</param>
        /// <param name="Data">对象</param>
        public void Append(string Key, string Value, object Data)
        {
            VonDataItem item = new VonDataItem(Key, Value, Data);
            if (currentItem.Data == null)
            {
                currentItem.Data = item;
                first = currentItem;
                laster = currentItem;
            }
            else
            {
                currentItem = new VonLinkerItem();
                currentItem.Data = item;
                currentItem.Prevous = laster;
                laster.Next = currentItem;
                laster = currentItem;
            }
            _Count++;
        }
        /// <summary>
        /// 在结束位置追加一个链接
        /// </summary>
        /// <param name="Key">键名</param>
        /// <param name="Value">键值</param>
        /// <param name="Data">对象</param>
        public void AddNext(string Key, string Value, object Data)
        {
            VonDataItem item = new VonDataItem(Key, Value, Data);
            if (currentItem.Data == null)
            {
                currentItem.Data = item;
                first = currentItem;
                laster = currentItem;
            }
            else
            {
                VonLinkerItem linker = new VonLinkerItem();
                linker.Data = item;
                linker.Prevous = currentItem;
                linker.Next = currentItem.Next;
                if (laster == currentItem) laster = linker;
                if (currentItem.Next != null) currentItem.Next.Prevous = linker;
                currentItem.Next = linker;
                currentItem = linker;
            }
            _Count++;
        }
        /// <summary>
        /// 在起始位置插入一个链接
        /// </summary>
        /// <param name="Key">键名</param>
        /// <param name="Value">键值</param>
        /// <param name="Data">对象</param>
        public void AddFirst(string Key, string Value, object Data)
        {
            VonDataItem item = new VonDataItem(Key, Value, Data);
            if (currentItem.Data == null)
            {
                currentItem.Data = item;
                first = currentItem;
                laster = currentItem;
            }
            else
            {
                currentItem = new VonLinkerItem();
                currentItem.Data = item;
                currentItem.Next = first;
                first.Prevous = currentItem;
                first = currentItem;
            }
            _Count++;
        }
        /// <summary>
        /// 在当前节点位置插入一个链接
        /// </summary>
        /// <param name="Key">键名</param>
        /// <param name="Value">键值</param>
        /// <param name="Data">对象</param>
        public void Insert(string Key, string Value, object Data)
        {
            VonDataItem item = new VonDataItem(Key, Value, Data);
            if (currentItem.Data == null)
            {
                currentItem.Data = item;
                first = currentItem;
                laster = currentItem;
            }
            else
            {
                VonLinkerItem linker = new VonLinkerItem();
                linker.Data = item;
                linker.Prevous = currentItem.Prevous;
                linker.Next = currentItem;
                if (first == currentItem) first = linker;
                if (currentItem.Prevous != null) currentItem.Prevous.Next = linker;
                currentItem.Prevous = linker;
                currentItem = linker;
            }
            _Count++;
        }
        /// <summary>
        /// 删除当前节点
        /// </summary>
        public void Delete()
        {
            if (currentItem.Data == null) return;
            VonLinkerItem item = currentItem;
            if (currentItem == first) first = item.Next;
            if (currentItem == laster) laster = item.Prevous;

            if (item.Next != null)
            {
                if (item.Prevous != null) item.Prevous.Next = item.Next;
                item.Next.Prevous = item.Prevous;
                currentItem = item.Next;
            }
            else if (item.Prevous != null)
            {
                currentItem = item.Prevous;
                currentItem.Next = null;
            }
            item.Data = null;
            item.Prevous = null;
            item.Next = null;
            _Count--;
        }
        #endregion
    }
    /// <summary>
    /// 对象键值集合{key}={value}+{data},{object}={object}+object
    /// </summary>
    public class VonObjectCollection : IListSource, IEnumerable
    {
        private List<VonObjectItem> datas = new List<VonObjectItem>();
        /// <summary>
        /// 数量
        /// </summary>
        public int Count
        {
            get { return datas.Count; }
        }
        /// <summary>
        /// 根据索引得到设定值
        /// </summary>
        /// <param name="Index">索引</param>
        /// <returns>返回值</returns>
        public VonObjectItem this[int Index]
        {
            get { return datas[Index]; }
            set { datas[Index] = value; }
        }
        /// <summary>
        /// 根据索引得到设定值
        /// </summary>
        /// <param name="Index">索引</param>
        /// <returns>返回值</returns>
        public VonObjectItem this[object Key]
        {
            get
            {
                int idx = IndexOf(Key);
                if (idx < 0) return null;
                else return this[idx];
            }
            set
            {
                int idx = IndexOf(Key);
                if (idx < 0) Add(Key, value.Value, value.Data);
                else
                {
                    this[idx].Value = value.Value;
                    this[idx].Data = value.Data;
                }
            }
        }
        /// <summary>
        /// 根据索引得到节点键值
        /// </summary>
        /// <param name="Index">索引</param>
        /// <returns>键值</returns>
        public object GetKey(int Index)
        {
            return datas[Index].Key;
        }
        /// <summary>
        /// 根据键值得到索引
        /// </summary>
        /// <param name="KeyValue">键值</param>
        /// <returns>索引</returns>
        public int IndexOf(object Key)
        {
            for (int i = 0; i < Count; i++)
            {
                if (datas[i].Key == Key) return i;
            }
            return -1;
        }
        /// <summary>
        /// 添加一个键值的节点
        /// </summary>
        /// <param name="Key">主键</param>
        /// <param name="Value">值</param>
        /// <returns>索引</returns>
        public int Add(object Key, object Value, object Data)
        {
            if (_UniqueKey)
            {
                int idx = IndexOf(Key);
                if (idx >= 0)
                {
                    datas[idx].Value = Value;
                    datas[idx].Data = Data;
                    return idx;
                }
            }
            datas.Add(new VonObjectItem(Key, Value, Data));
            return Count - 1;
        }
        /// <summary>
        /// 添加一个键值的节点
        /// </summary>
        /// <param name="Key">主键</param>
        /// <param name="Value">值</param>
        /// <returns>索引</returns>
        public void Insert(int Index, object Key, object Value, object Data)
        {
            if (_UniqueKey)
            {
                int idx = IndexOf(Key);
                if (idx >= 0)
                {
                    datas[idx].Value = Value;
                    datas[idx].Data = Data;
                    return;
                }
            }
            VonObjectItem item = new VonObjectItem(Key, Value, Data);
            for (int i = Index; i < Count; i++)
            {
                VonObjectItem orgItem = datas[i];
                datas[i] = item;
                item = orgItem;
            }
            datas.Add(item);
        }
        /// <summary>
        /// 删除值
        /// </summary>
        /// <param name="Index"></param>
        public void Delete(int Index)
        {
            datas.RemoveAt(Index);
        }
        /// <summary>
        /// 根据主键删除一个节点
        /// </summary>
        /// <param name="Key"></param>
        public void Delete(string Key)
        {
            datas.RemoveAt(IndexOf(Key));
        }
        /// <summary>
        /// 清除所有数据
        /// </summary>
        public void Clear()
        {
            datas = new List<VonObjectItem>();
        }
        /// <summary>
        /// 移动一个节点
        /// </summary>
        /// <param name="Org">原始位置</param>
        /// <param name="Dest">目标位置</param>
        public void Move(int Org, int Dest)
        {
            int step = Org > Dest ? -1 : 1;
            VonObjectItem item = datas[Org];
            while (Org != Dest)
            {
                datas[Org] = datas[Org + step];
                Org += step;
            }
            datas[Dest] = item;
        }
        /// <summary>
        /// 主键是否采用唯一机制，默认是唯一，不允许重复
        /// </summary>
        public bool UniqueKey { get { return _UniqueKey; } set { _UniqueKey = value; } }
        private bool _UniqueKey = true;

        public bool ContainsListCollection
        {
            get { return false; }
        }

        public IList GetList()
        {
            return datas;
        }

        public IEnumerator GetEnumerator()
        {
            return new EVonObjectCollection(datas);
        }
    }
    /// <summary>
    /// 为 VonObjectCollection 支持foreach循环建立的 IEnumerator 接口类
    /// </summary>
    internal class EVonObjectCollection : IEnumerator
    {
        public List<VonObjectItem> datas;
        public EVonObjectCollection(List<VonObjectItem> collection)
        {
            this.datas = collection;
        }
        int position = -1;

        public bool MoveNext()
        {
            position++;
            return position < datas.Count;
        }
        public void Reset()
        {
            position = -1;
        }
        public object Current
        {
            get
            {
                try
                {
                    return datas[position];
                }
                catch
                {
                    throw new InvalidOperationException();
                }
            }
        }
    }
    /// <summary>
    /// 对象键值集合(Key=Value)，默认文本输出格式为：{key}#3{value}$5
    /// </summary>
    public class VonKeyValueCollection : IListSource, IEnumerable
    {
        private List<VonKeyValueItem> datas = new List<VonKeyValueItem>();
        public VonKeyValueCollection() { }
        public VonKeyValueCollection(char ADelimiter, char ATermination)
        {
            _Termination = ATermination;
            _Delimiter = ADelimiter;
        }
        /// <summary>
        /// 数量
        /// </summary>
        public int Count
        {
            get { return datas.Count; }
        }
        /// <summary>
        /// 键值间隔符
        /// </summary>
        public char Delimiter
        {
            set { _Delimiter = value; }
            get { return _Delimiter; }
        }
        private char _Delimiter = (char)3;
        /// <summary>
        /// 行终止符
        /// </summary>
        public char Termination
        {
            get { return _Termination; }
            set { _Termination = value; }
        }
        private char _Termination = (char)5;
        /// <summary>
        /// 设置或获取记录内容文本化，默认间隔符是{key}#3{value}#5...
        /// </summary>
        public string Text
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                foreach (VonKeyValueItem item in datas)
                {
                    sb.Append(item.Key + _Delimiter + item.Value + _Termination);
                }
                return sb.ToString();
            }
            set
            {
                Clear();
                if (value == null) return;
                string[] lst = value.Split(_Termination);
                foreach (string s in lst)
                {
                    int pos = s.IndexOf(_Delimiter);
                    if (pos < 0) continue;
                    else Add(s.Substring(0, pos), s.Substring(pos + 1));
                }
            }
        }
        /// <summary>
        /// 根据索引得到设定值
        /// </summary>
        /// <param name="Index">索引</param>
        /// <returns>返回值</returns>
        public VonKeyValueItem this[int Index]
        {
            get { return datas[Index]; }
            set { datas[Index] = value; }
        }
        /// <summary>
        /// 根据索引得到设定值
        /// </summary>
        /// <param name="Index">索引</param>
        /// <returns>返回值</returns>
        public string this[string Key]
        {
            get
            {
                int idx = IndexOf(Key);
                if (idx < 0) return null;
                else return this[idx].Value;
            }
            set
            {
                int idx = IndexOf(Key);
                if (idx < 0) Add(Key, value);
                else this[idx].Value = value;
            }
        }
        /// <summary>
        /// 根据索引得到节点键值
        /// </summary>
        /// <param name="Index">索引</param>
        /// <returns>键值</returns>
        public string GetKey(int Index)
        {
            return datas[Index].Key;
        }
        /// <summary>
        /// 根据键值得到索引
        /// </summary>
        /// <param name="KeyValue">键值</param>
        /// <returns>索引</returns>
        public int IndexOf(string Key)
        {
            for (int i = 0; i < Count; i++)
            {
                if (datas[i].Key.Equals(Key, StringComparison.OrdinalIgnoreCase)) return i;
            }
            return -1;
        }
        /// <summary>
        /// 添加一个键值的节点
        /// </summary>
        /// <param name="Key">主键</param>
        /// <param name="Value">值</param>
        /// <returns>索引</returns>
        public int Add(string Key, string Value)
        {
            if (_UniqueKey)
            {
                int idx = IndexOf(Key);
                if (idx >= 0)
                {
                    datas[idx].Value = Value;
                    return idx;
                }
            }
            datas.Add(new VonKeyValueItem(Key, Value));
            return Count - 1;
        }
        /// <summary>
        /// 添加一个键值的节点
        /// </summary>
        /// <param name="Key">主键</param>
        /// <param name="Value">值</param>
        /// <returns>索引</returns>
        public void Insert(int Index, string Key, string Value)
        {
            if (_UniqueKey)
            {
                int idx = IndexOf(Key);
                if (idx >= 0)
                {
                    datas[idx].Value = Value;
                    return;
                }
            }
            VonKeyValueItem item = new VonKeyValueItem(Key, Value);
            for (int i = Index; i < Count; i++)
            {
                VonKeyValueItem orgItem = datas[i];
                datas[i] = item;
                item = orgItem;
            }
            datas.Add(item);
        }
        /// <summary>
        /// 删除值
        /// </summary>
        /// <param name="Index"></param>
        public void Delete(int Index)
        {
            datas.RemoveAt(Index);
        }
        /// <summary>
        /// 根据主键删除一个节点
        /// </summary>
        /// <param name="Key"></param>
        public void Delete(string Key)
        {
            datas.RemoveAt(IndexOf(Key));
        }
        /// <summary>
        /// 清除所有数据
        /// </summary>
        public void Clear()
        {
            datas = new List<VonKeyValueItem>();
        }
        /// <summary>
        /// 移动一个节点
        /// </summary>
        /// <param name="Org">原始位置</param>
        /// <param name="Dest">目标位置</param>
        public void Move(int Org, int Dest)
        {
            int step = Org > Dest ? -1 : 1;
            VonKeyValueItem item = datas[Org];
            while (Org != Dest)
            {
                datas[Org] = datas[Org + step];
                Org += step;
            }
            datas[Dest] = item;
        }
        /// <summary>
        /// 主键是否采用唯一机制，默认是唯一，不允许重复
        /// </summary>
        public bool UniqueKey { get { return _UniqueKey; } set { _UniqueKey = value; } }
        private bool _UniqueKey = true;
        public bool ContainsListCollection
        {
            get { return false; }
        }

        public IList GetList()
        {
            return datas;
        }

        public IEnumerator GetEnumerator()
        {
            return datas.GetEnumerator();
            //return new EVonKeyValueCollection(datas);
        }
    }
    /// <summary>
    /// 为 VonKeyValueCollection 支持foreach循环建立的 IEnumerator 接口类
    /// </summary>
    internal class EVonKeyValueCollection : IEnumerator
    {
        public List<VonKeyValueItem> datas;
        public EVonKeyValueCollection(List<VonKeyValueItem> collection)
        {
            this.datas = collection;
        }
        int position = -1;

        public bool MoveNext()
        {
            position++;
            return position < datas.Count;
        }
        public void Reset()
        {
            position = -1;
        }
        public object Current
        {
            get
            {
                try
                {
                    return datas[position];
                }
                catch
                {
                    throw new InvalidOperationException();
                }
            }
        }
    }
    /// <summary>
    /// 字符键值集合(含应用对象)
    /// </summary>
    public class VonStringCollection : IListSource, IEnumerable
    {
        private List<VonDataItem> datas = new List<VonDataItem>();
        /// <summary>
        /// 使用默认间隔符间隔数据的解析格式（key=value[\t...]）
        /// </summary>
        public VonStringCollection()
        {

        }
        /// <summary>
        /// 使用自定义间隔符间隔数据的解析格式（key=value[\t...]）
        /// </summary>
        public VonStringCollection(char Delimiter, char Termination)
        {
            this.Delimiter = Delimiter;
            this.Termination = Termination;
        }
        /// <summary>
        /// 数量
        /// </summary>
        public int Count
        {
            get { return datas.Count; }
        }
        /// <summary>
        /// 根据索引得到设定值
        /// </summary>
        /// <param name="Index">索引</param>
        /// <returns>返回值</returns>
        public string this[int Index]
        {
            get { return datas[Index].Value; }
            set { datas[Index].Value = value; }
        }
        /// <summary>
        /// 根据索引得到设定值
        /// </summary>
        /// <param name="Index">索引</param>
        /// <returns>返回值</returns>
        public string this[string Key]
        {
            get
            {
                int idx = IndexOfKey(Key);
                if (idx < 0) return "";
                else return this[idx];
            }
            set
            {
                int idx = IndexOfKey(Key);
                if (idx < 0) Add(Key, value, null);
                else this[idx] = value;
            }
        }
        /// <summary>
        /// 根据索引得到索引的键值
        /// </summary>
        /// <param name="Index">索引</param>
        /// <returns></returns>
        public string GetKey(int Index)
        {
            return datas[Index].Key;
        }
        /// <summary>
        /// 得到存储的对象
        /// </summary>
        /// <param name="Key"></param>
        /// <returns></returns>
        public object GetObject(string Key)
        {
            int idx = IndexOfKey(Key);
            if (idx < 0) return null;
            else return datas[idx].Data;
        }
        /// <summary>
        /// 得到存储的对象
        /// </summary>
        /// <param name="Index"></param>
        /// <returns></returns>
        public object GetObject(int Index)
        {
            return datas[Index].Data;
        }
        /// <summary>
        /// 设置存储的对象
        /// </summary>
        /// <param name="Index">索引</param>
        /// <param name="Data">关联对象</param>
        public void SetObject(int Index, object Data)
        {
            datas[Index].Data = Data;
        }
        /// <summary>
        /// 更改键值
        /// </summary>
        /// <param name="Index">索引</param>
        /// <param name="Key">新键值</param>
        public void SetKey(int Index, string Key)
        {
            datas[Index].Key = Key;
        }
        /// <summary>
        /// 根据存储的对象得到记录索引
        /// </summary>
        /// <param name="Data">对象</param>
        /// <returns>索引</returns>
        public int IndexOfObject(object Data)
        {
            for (int i = 0; i < Count; i++)
            {
                if (datas[i].Data.Equals(Data)) return i;
            }
            return -1;
        }
        /// <summary>
        /// 根据存储的值得到记录索引
        /// </summary>
        /// <param name="Value">对象</param>
        /// <returns>索引</returns>
        public int IndexOfValue(string Value)
        {
            for (int i = 0; i < Count; i++)
            {
                if (datas[i].Value.Equals(Value, StringComparison.OrdinalIgnoreCase)) return i;
            }
            return -1;
        }
        /// <summary>
        /// 根据键值得到索引
        /// </summary>
        /// <param name="KeyValue">键值</param>
        /// <returns>索引</returns>
        public int IndexOfKey(string Key)
        {
            for (int i = 0; i < Count; i++)
            {
                if (datas[i].Key.Equals(Key, StringComparison.OrdinalIgnoreCase)) return i;
            }
            return -1;
        }
        /// <summary>
        /// 添加一个键值
        /// </summary>
        /// <param name="keyValue">键值内容，例如：RED=3453455</param>
        /// <returns></returns>
        public int Add(string keyValue)
        {
            string[] kv = keyValue.Split(Delimiter);
            switch (kv.Length)
            {
                case 1: return Add(kv[0], "", null);
                case 2: return Add(kv[0], kv[1], null);
                default: return 0;
            }

        }
        /// <summary>
        /// 添加一个键值的节点
        /// </summary>
        /// <param name="Key">主键</param>
        /// <param name="Value">值</param>
        /// <returns>索引</returns>
        public int Add(string Key, string Value)
        {
            return Add(Key, Value, null);
        }
        /// <summary>
        /// 添加一个键值的节点
        /// </summary>
        /// <param name="Key">主键</param>
        /// <param name="Value">值</param>
        /// <param name="Data">对象</param>
        /// <returns>索引</returns>
        public int Add(string Key, string Value, object Data)
        {
            int idx = IndexOfKey(Key);
            VonDataItem Item;
            if (idx >= 0)
            {
                Item = datas[idx];
                Item.Value = Value;
                Item.Data = Data;
                return idx;
            }
            else
            {
                Item = new VonDataItem(Key, Value, Data);
                datas.Add(Item);
                return Count - 1;
            }
        }
        /// <summary>
        /// 添加一组键值的节点
        /// </summary>
        /// <param name="lst">键值组</param>
        public void Add(VonStringCollection lst)
        {
            foreach (VonDataItem item in lst.datas)
            {
                datas.Add(item);
            }
        }
        /// <summary>
        /// 保存一个节点信息,如果发现重复键值则替换，没有则添加
        /// </summary>
        /// <param name="Key">键值</param>
        /// <param name="Value">内容</param>
        /// <param name="Data">数据</param>
        /// <returns></returns>
        public int Save(string Key, string Value, object Data)
        {
            int idx = IndexOfKey(Key);
            if (idx < 0) return Add(Key, Value, Data);
            datas[idx].Value = Value;
            datas[idx].Data = Data;
            return idx;
        }
        /// <summary>
        /// 添加一个键值的节点
        /// </summary>
        /// <param name="Key">主键</param>
        /// <param name="Value">值</param>
        /// <returns>索引</returns>
        public void Insert(int Index, string Key, string Value, object Data)
        {
            VonDataItem newItem = new VonDataItem();
            newItem.Key = Key;
            newItem.Value = Value;
            newItem.Data = Data;
            VonDataItem item = newItem;
            VonDataItem orgItem = datas[Index];
            for (int i = Index; i < Count; i++)
            {
                orgItem = datas[Index];
                datas[Index] = item;
                item = orgItem;
            }
            datas.Add(orgItem);
        }
        /// <summary>
        /// 删除值
        /// </summary>
        /// <param name="Index"></param>
        public void Delete(int Index)
        {
            datas.RemoveAt(Index);
        }
        /// <summary>
        /// 根据主键删除一个节点
        /// </summary>
        /// <param name="Key"></param>
        public void Delete(string Key)
        {
            datas.RemoveAt(IndexOfKey(Key));
        }
        /// <summary>
        /// 文本输出或导入采用时键与值之间的间隔符，默认为“=”
        /// </summary>
        public char Delimiter
        {
            get { return _Delimiter; }
            set { _Delimiter = value; }
        }
        private char _Delimiter = '=';
        /// <summary>
        /// 文本输出或导入采用的间隔符，默认为tab
        /// </summary>
        public char Termination
        {
            get { return _Termination; }
            set { _Termination = value; }
        }
        private char _Termination = '\t';
        /// <summary>
        /// 转换为文本格式，间隔符号根据Delimiter来定义
        /// </summary>
        public string Text
        {
            get
            {
                StringBuilder S = new StringBuilder();
                foreach (VonDataItem item in datas)
                {
                    S.Append(_Termination + item.Key + _Delimiter + item.Value);
                }
                if (S.Length > 0)
                    return S.Remove(0, 1).ToString();
                else return "";
            }
            set
            {
                datas.Clear();
                string key = "";
                string vl = "";
                foreach (char c in value)
                {
                    if (c == _Termination)
                    {
                        VonDataItem item = new VonDataItem();
                        item.Key = key;
                        item.Value = vl;
                        datas.Add(item);
                        key = "";
                        vl = "";
                    }
                    else if (c == _Delimiter)
                    {
                        key = vl;
                        vl = "";
                    }
                    else { vl += c; }
                }
                if (key.Trim() != "")
                {
                    VonDataItem item = new VonDataItem();
                    item.Key = key;
                    item.Value = vl;
                    datas.Add(item);
                }
            }
        }
        /// <summary>
        /// 获得键值文本，以_Delimiter间隔
        /// </summary>
        public string KeyText
        {
            get
            {
                StringBuilder S = new StringBuilder();
                foreach (VonDataItem item in datas)
                {
                    S.Append(_Termination + item.Key);
                }
                return S.Remove(0, 1).ToString();
            }
        }
        /// <summary>
        /// 是否包含List，实现 IListSource 的方法
        /// </summary>
        public bool ContainsListCollection
        {
            get { return true; }
        }
        /// <summary>
        /// 返回 List 集合，实现 IListSource 的方法
        /// </summary>
        public IList GetList()
        {
            return datas;
        }
        /// <summary>
        /// 返回枚举方法，实现 IEnumerable 的方法
        /// </summary>
        public IEnumerator GetEnumerator()
        {
            return datas.GetEnumerator();
        }
    }
    /// <summary>
    /// windows ini类型配置信息管理类
    /// </summary>
    public class VonConfigCollection
    {
        Hashtable tb = new Hashtable();
        private bool modified = false;
        /// <summary>
        /// 文件格式，设置后系统完成文件内容读取，释放时，系统完成修改后的存储
        /// </summary>
        public string Filename
        {
            get { return _Filename; }
            set
            {
                tb.Clear();
                _Filename = Filename;
                using (StreamReader sr = new StreamReader(Filename, System.Text.Encoding.Default, true))
                {
                    String line;
                    NameValueCollection currentTB = null;
                    while ((line = sr.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line == "" || line[0] == ';') continue;
                        if (line[0] == '[')
                        {
                            currentTB = new NameValueCollection();
                            tb.Add(line.Substring(1, line.Length - 2), currentTB);//line.Substring(2, line.Length - 2) = copy(line, 2, strln(line) - 2)
                        }
                        else
                        {
                            int pos = line.IndexOf('=');
                            string ident = line.Substring(0, pos);
                            string vl = line.Substring(pos + 1, line.Length - pos - 1);
                            currentTB.Add(ident, vl);
                        }
                    }
                }
            }
        }
        private string _Filename = "";
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="Filename">ini配置文件名称</param>
        public VonConfigCollection()
        {
        }
        /// <summary>
        /// 全部配置信息文本
        /// </summary>
        public string Text
        {
            get
            {
                StringBuilder s = new StringBuilder();
                NameValueCollection currentTB = null;
                foreach (DictionaryEntry de in tb)
                {
                    currentTB = (NameValueCollection)de.Value;
                    s.AppendLine("[" + de.Key + "]");
                    for (int i = 0; i < currentTB.Count; i++)
                        s.AppendLine(currentTB.Keys[i] + "=" + currentTB[i]);
                }
                return s.ToString();
            }
            set
            {
                tb.Clear();
                StringBuilder s = new StringBuilder();
                string key = null;
                NameValueCollection currentTB = null;
                foreach (char c in value)
                {
                    if (c == '[')
                    {
                        if (key != null)
                        {
                            currentTB.Add(key, s.ToString());
                            s.Length = 0;
                            key = null;
                        }
                    }
                    else if (c == ']')
                    {
                        currentTB = new NameValueCollection();
                        tb.Add(s.ToString(), currentTB);
                        s.Length = 0;
                    }
                    else if (c == '=')
                    {
                        if (s[0] != ';') key = s.ToString();
                        s.Length = 0;
                    }
                    else if (c == '\r' || c == '\n')
                    {
                        if (key != null)
                        {
                            currentTB.Add(key, s.ToString());
                            key = null;
                        }
                        s.Length = 0;
                    }
                    else s.Append(c);
                }
                if (key != null)
                {
                    currentTB.Add(key, s.ToString());
                }
            }
        }
        /// <summary>
        /// 当前段落数量
        /// </summary>
        public int SectionCount
        {
            get { return tb.Count; }
        }
        /// <summary>
        /// 检查段落是否存在
        /// </summary>
        /// <param name="SectionName"></param>
        /// <returns></returns>
        public bool ExistSection(string SectionName)
        {
            return tb.ContainsKey(SectionName);
        }
        /// <summary>
        /// 检查段落值是否存在
        /// </summary>
        /// <param name="SectionName"></param>
        /// <returns></returns>
        public bool ExistIdent(string SectionName, string Ident)
        {
            return tb.ContainsKey(SectionName) && ((NameValueCollection)tb[SectionName])[Ident] != null;
        }
        /// <summary>
        /// 段落中内容的数量
        /// </summary>
        /// <param name="SectionName">段落名称</param>
        /// <returns></returns>
        public int IdentCount(string SectionName)
        {
            NameValueCollection identTable = (NameValueCollection)tb[SectionName];
            if (identTable == null) return 0;
            return identTable.Count;
        }
        /// <summary>
        /// 根据段落名称得到段落内容
        /// </summary>
        /// <param name="SectionName"></param>
        /// <returns></returns>
        public NameValueCollection GetSection(string SectionName)
        {
            return (NameValueCollection)tb[SectionName];
        }
        /// <summary>
        /// 得到一个ini文件配置字符值
        /// </summary>
        /// <param name="Section">段落名称</param>
        /// <param name="Ident">配置名称</param>
        /// <param name="Value">缺省值</param>
        /// <returns>配置值</returns>
        public string ReadString(string Section, string Ident, string Value)
        {
            NameValueCollection identTable = (NameValueCollection)tb[Section];
            if (identTable == null) return Value;
            string result = identTable[Ident];
            if (result == null) return Value;
            return result;
        }
        /// <summary>
        /// 得到一个ini文件配置整数值
        /// </summary>
        /// <param name="Section">段落名称</param>
        /// <param name="Ident">配置名称</param>
        /// <param name="Value">缺省值</param>
        /// <returns>配置值</returns>
        public int ReadInteger(string Section, string Ident, int Value)
        {
            return int.Parse(ReadString(Section, Ident, Value.ToString()));
        }
        /// <summary>
        /// 得到一个ini文件配置浮点值
        /// </summary>
        /// <param name="Section">段落名称</param>
        /// <param name="Ident">配置名称</param>
        /// <param name="Value">缺省值</param>
        /// <returns>配置值</returns>
        public double ReadDouble(string Section, string Ident, double Value)
        {
            return double.Parse(ReadString(Section, Ident, Value.ToString()));
        }
        /// <summary>
        /// 得到一个ini文件配置布尔值
        /// </summary>
        /// <param name="Section">段落名称</param>
        /// <param name="Ident">配置名称</param>
        /// <param name="Value">缺省值</param>
        /// <returns>配置值</returns>
        public bool ReadBoolean(string Section, string Ident, bool Value)
        {
            return bool.Parse(ReadString(Section, Ident, Value.ToString()));
        }
        /// <summary>
        /// 得到一个ini文件配置日期值
        /// </summary>
        /// <param name="Section">段落名称</param>
        /// <param name="Ident">配置名称</param>
        /// <param name="Value">缺省值</param>
        /// <returns>配置值</returns>
        public DateTime ReadBDatetime(string Section, string Ident, DateTime Value)
        {
            return DateTime.Parse(ReadString(Section, Ident, Value.ToString()));
        }
        /// <summary>
        /// 得到所有段落名称列表
        /// </summary>
        /// <returns>段落名称列表</returns>
        public ArrayList ReadSections()
        {
            ArrayList result = new ArrayList();
            foreach (DictionaryEntry sc in tb)
            {
                result.Add(sc.Key);
            }
            return result;
        }
        /// <summary>
        /// 到段落中设置项目的名称列表
        /// </summary>
        /// <param name="Section">段落名称</param>
        /// <returns>项目的名称列表</returns>)
        public ArrayList ReadSectionIdents(string Section)
        {
            ArrayList result = new ArrayList();
            NameValueCollection identTable = (NameValueCollection)tb[Section];
            if (identTable == null) return result;
            for (int i = 0; i < identTable.Count; i++)
            {
                result.Add(identTable.Keys[i]);
            }
            return result;
        }
        /// <summary>
        /// 设置一个ini文件配置字符值
        /// </summary>
        /// <param name="Section">段落名称</param>
        /// <param name="Ident">配置名称</param>
        /// <param name="Value">配置值</param>
        public void WriteString(string Section, string Ident, string Value)
        {
            NameValueCollection identTable = (NameValueCollection)tb[Section];
            if (identTable == null)
            {
                identTable = new NameValueCollection();
                tb.Add(Section, identTable);
            }
            if (identTable[Ident] == null)
            {
                identTable.Add(Ident, Value);
            }
            else identTable[Ident] = Value;
            modified = true;
        }
        /// <summary>
        /// 设置一个ini文件配置整数值
        /// </summary>
        /// <param name="Section">段落名称</param>
        /// <param name="Ident">配置名称</param>
        /// <param name="Value">配置值</param>
        public void WriteInteger(string Section, string Ident, int Value)
        {
            WriteString(Section, Ident, Value.ToString());
        }
        /// <summary>
        /// 设置一个ini文件配置浮点值
        /// </summary>
        /// <param name="Section">段落名称</param>
        /// <param name="Ident">配置名称</param>
        /// <param name="Value">配置值</param>
        public void WriteDouble(string Section, string Ident, double Value)
        {
            WriteString(Section, Ident, Value.ToString());
        }
        /// <summary>
        /// 设置一个ini文件配置日期值
        /// </summary>
        /// <param name="Section">段落名称</param>
        /// <param name="Ident">配置名称</param>
        /// <param name="Value">配置值</param>
        public void WriteDatetime(string Section, string Ident, DateTime Value)
        {
            WriteString(Section, Ident, Value.ToString());
        }
        /// <summary>
        /// 设置一个ini文件配置布尔值
        /// </summary>
        /// <param name="Section">段落名称</param>
        /// <param name="Ident">配置名称</param>
        /// <param name="Value">配置值</param>
        public void WriteBoolean(string Section, string Ident, bool Value)
        {
            WriteString(Section, Ident, Value.ToString());
        }
        /// <summary>
        /// 析构函数，存储修改过的ini配置文件信息　
        /// </summary>
        ~VonConfigCollection()
        {
            if (_Filename == "") return;
            if (!modified) return;
            using (StreamWriter sw = new StreamWriter(_Filename))
            {
                foreach (DictionaryEntry sc in tb)
                {
                    string sectionName = (string)sc.Key;
                    NameValueCollection identTable = (NameValueCollection)sc.Value;
                    sw.WriteLine("[" + sectionName + "]");
                    for (int i = 0; i < identTable.Count; i++)
                    {
                        sw.WriteLine(identTable.Keys[i] + "=" + identTable.Get(0));
                    }
                }
            }
        }
    }
    /// <summary>
    /// 参数设置间隔符方案
    /// </summary>
    /// <example>EVPDS_Custom:用户手动定义的间隔符</example>   
    /// <example>EVPDS_Comma:{section}:{key}={value},...\r</example>   
    /// <example>EVPDS_Semicolon:{section}:{key}={value};...\r</example>
    /// <example>EVPDS_Bracket:{section}={key}({value})...\r</example>
    /// <example>EVPDS_Special:{section}#3{key}#4{value}#5...#7</example>
    public enum EVonParamDelimiterScheme
    {
        /// <summary>
        /// 用户手动定义的间隔符
        /// </summary>
        EVPDS_Custom,
        /// <summary>
        /// {section}:{key}={value},...\r
        /// </summary>
        EVPDS_Comma,
        /// <summary>
        /// {section}:{key}={value};...\r
        /// </summary>
        EVPDS_Semicolon,
        /// <summary>
        /// {section}={key}({value})...\r
        /// </summary>
        EVPDS_Bracket,
        /// <summary>
        /// {section}#3{key}#4{value}#5...#7
        /// </summary>
        EVPDS_Special
    }
    /// <summary>
    /// 参数集合支持 name=key1(value1)key2(value2)...，同样也支持name=key1=value1,key2=value2,...，或者name#3key1#3value1#3key2#3value2#3...#4
    /// </summary>
    public class VonParamItem : IListSource, IEnumerable
    {
        List<VonKeyValueItem> items = new List<VonKeyValueItem>();
        /// <summary>
        /// 段落名称
        /// </summary>
        public string ParamName { get; set; }
        /// <summary>
        /// 段落对象
        /// </summary>
        public object ParamData { get; set; }
        private char _KeyFlag, _ValueFlag, _NameFlag;
        public VonParamItem(char NameFlag, char KeyFlag, char ValueFlag)
        {
            _NameFlag = NameFlag;
            _KeyFlag = KeyFlag;
            _ValueFlag = ValueFlag;
        }
        /// <summary>
        /// 添加一个键值
        /// </summary>
        /// <param name="key">键名</param>
        /// <param name="value">键值</param>
        public void Add(string key, string value)
        {
            foreach (VonKeyValueItem item in items)
            {
                if (item.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    item.Value = value;
                    return;
                }
            }
            VonKeyValueItem newItem = new VonKeyValueItem(key, value);
            items.Add(newItem);
        }
        /// <summary>
        /// 删除一个键值 
        /// </summary>
        /// <param name="key">键名</param>
        public void Delete(string key)
        {
            foreach (VonKeyValueItem item in items)
            {
                if (item.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    items.Remove(item);
                    return;
                }
            }
        }
        /// <summary>
        /// 清除所有键值
        /// </summary>
        public void Clear()
        {
            items.Clear();
        }
        /// <summary>
        /// 读取键值
        /// </summary>
        /// <param name="key">键名</param>
        /// <returns>键值</returns>
        public string ReadValue(string key)
        {
            foreach (VonKeyValueItem item in items)
            {
                if (item.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                {
                    return item.Value;
                }
            }
            return "";
        }
        /// <summary>
        /// 得到一个参数的文字内容
        /// </summary>
        /// <returns></returns>
        public string GetText(char NameFlag, char KeyFlag, char ValueFlag)
        {
            StringBuilder sb = new StringBuilder();
            foreach (VonKeyValueItem item in items)
            {
                sb.Append(item.Key + KeyFlag + item.Value + ValueFlag);
            }
            //sb.Remove(0, 1);
            return ParamName + NameFlag + sb.ToString();
        }
        /// <summary>
        /// 将一个文字内容反写回本类中
        /// </summary>
        /// <param name="value">文字</param>
        /// <param name="Idx">开始拾取位置</param>
        /// <param name="endFlag">结束字符符集，例如："\r"或是"\n"或是";"等</param>
        /// <returns></returns>
        public int SetText(string value, int Idx, char NameFlag, char KeyFlag, char ValueFlag, char endFlag)
        {
            // read a name from value
            ParamName = "";
            while (value[Idx] != NameFlag)
            {
                ParamName += value[Idx];
                Idx++;
            }
            // read params from value
            items.Clear();
            string szK = "";
            string szV = "";
            for (int i = Idx + 1; i < value.Length; i++)
            {
                if (value[i] == KeyFlag)
                {
                    szK = szV;
                    szV = "";
                    continue;
                }
                else if (value[i] == ValueFlag)
                {
                    VonKeyValueItem item = new VonKeyValueItem(szK, szV);
                    items.Add(item);
                    szK = "";
                    szV = "";
                    continue;
                }
                else if (value[i] == endFlag)
                {
                    return i + 1;
                }
                szV += value[i];
            }
            return value.Length;
        }

        public bool ContainsListCollection
        {
            get
            {
                return true;
            }
        }
        public IList GetList()
        {
            return items;
        }

        public IEnumerator GetEnumerator()
        {
            return items.GetEnumerator();
        }
    }
    /// <summary>
    /// 含键值的参数集合，例如：name=key1(value1)key2(value2)...，同样也支持name=key1=value1,key2=value2,...，或者name#3key1#3value1#3key2#3value2#3...#4
    /// </summary>
    public class VonParamCollection
    {
        public List<VonParamItem> keyParams = new List<VonParamItem>();
        /// <summary>
        /// 名称和内容的间隔符
        /// </summary>
        public char NameFlag
        {
            get { return _NameFlag; }
            set { _NameFlag = value; _TextScheme = EVonParamDelimiterScheme.EVPDS_Custom; }
        }
        private char _NameFlag = '=';
        /// <summary>
        /// 键值对的间隔符
        /// </summary>
        public char KeyFlag
        {
            get { return _KeyFlag; }
            set { _KeyFlag = value; _TextScheme = EVonParamDelimiterScheme.EVPDS_Custom; }
        }
        private char _KeyFlag = '(';
        /// <summary>
        /// 键值对的结束符
        /// </summary>
        public char ValueFlag
        {
            get { return _ValueFlag; }
            set { _ValueFlag = value; _TextScheme = EVonParamDelimiterScheme.EVPDS_Custom; }
        }
        private char _ValueFlag = ')';
        /// <summary>
        /// 段落结束标识
        /// </summary>
        public char EndFlag
        {
            get { return _EndFlag; }
            set { _EndFlag = value; _TextScheme = EVonParamDelimiterScheme.EVPDS_Custom; }
        }
        private char _EndFlag = '\n';
        public EVonParamDelimiterScheme TextScheme
        {
            get { return _TextScheme; }
            set
            {
                _TextScheme = value;
                switch (_TextScheme)
                {
                    case EVonParamDelimiterScheme.EVPDS_Comma: _NameFlag = ':'; _KeyFlag = '='; _ValueFlag = ','; _EndFlag = '\n'; break;
                    case EVonParamDelimiterScheme.EVPDS_Semicolon: _NameFlag = ':'; _KeyFlag = '='; _ValueFlag = ';'; _EndFlag = '\n'; break;
                    case EVonParamDelimiterScheme.EVPDS_Bracket: _NameFlag = '='; _KeyFlag = '('; _ValueFlag = ')'; _EndFlag = '\n'; break;
                    case EVonParamDelimiterScheme.EVPDS_Special: _NameFlag = (char)3; _KeyFlag = (char)4; _ValueFlag = (char)5; _EndFlag = (char)7; break;
                }
            }
        }
        private EVonParamDelimiterScheme _TextScheme = EVonParamDelimiterScheme.EVPDS_Bracket;
        /// <summary>
        /// 根据索引得到设定值
        /// </summary>
        /// <param name="Index">索引</param>
        /// <returns>返回值</returns>
        public VonParamItem this[int Index]
        {
            get { return keyParams[Index]; }
            set
            {
                keyParams[Index] = value;
            }
        }
        /// <summary>
        /// 根据索引得到设定值
        /// </summary>
        /// <param name="ParamName">段落名称</param>
        /// <returns>返回值</returns>
        public VonParamItem this[string ParamName]
        {
            get
            {
                foreach (VonParamItem param in keyParams)
                {
                    if (param.ParamName.Equals(ParamName, StringComparison.OrdinalIgnoreCase))
                        return param;
                }
                return null;
            }
            set
            {
                foreach (VonParamItem param in keyParams)
                {
                    if (param.ParamName.Equals(ParamName, StringComparison.OrdinalIgnoreCase))
                    {
                        keyParams.Remove(param);
                        break;
                    }
                }
                keyParams.Add(value);
            }
        }
        /// <summary>
        /// 保存一个参数值
        /// </summary>
        /// <param name="ParamName">段落名称</param>
        /// <param name="Key">键名</param>
        /// <param name="Value">键值</param>
        /// <returns></returns>
        public void Save(string ParamName, string Key, string Value)
        {
            VonParamItem item = null;
            foreach (VonParamItem param in keyParams)
            {
                if (param.ParamName.Equals(ParamName, StringComparison.OrdinalIgnoreCase))
                {
                    item = param;
                    break;
                }
            }
            if (item == null)
            {
                item = new VonParamItem(_NameFlag, _KeyFlag, _ValueFlag);
                keyParams.Add(item);
            }
            item.ParamName = ParamName;
            item.Add(Key, Value);
        }
        /// <summary>
        /// 提取所有内容中指定段落中键值 
        /// </summary>
        /// <param name="ParamName"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public string Read(string ParamName, string Key)
        {
            foreach (VonParamItem param in keyParams)
            {
                if (param.ParamName.Equals(ParamName, StringComparison.OrdinalIgnoreCase))
                {
                    return param.ReadValue(Key);
                }
            }
            return "";
        }
        /// <summary>
        /// 得到该类的存储值
        /// </summary>
        /// <returns></returns>
        public string GetText()
        {
            StringBuilder sb = new StringBuilder();
            foreach (VonParamItem item in keyParams)
            {
                sb.Append(_EndFlag + item.GetText(_NameFlag, _KeyFlag, _ValueFlag));
            }
            sb.Remove(0, 1);
            return sb.ToString();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="idx"></param>
        /// <returns></returns>
        public int SetText(string value, int idx)
        {
            keyParams.Clear();
            while (idx < value.Length && value[idx] != _EndFlag)
            {
                VonParamItem newItem = new VonParamItem(_KeyFlag, _ValueFlag, _EndFlag);
                idx = newItem.SetText(value, idx, _NameFlag, _KeyFlag, _ValueFlag, _EndFlag) + 1;
                keyParams.Add(newItem);
            }
            return idx + 1;
        }
    }
    internal class VonCellItem
    {
        public List<string> cells = new List<string>();
    }
    public class VonTable //: IListSource, IEnumerable
    {
        private List<VonCellItem> rows = new List<VonCellItem>();
        /// <summary>
        /// 行数
        /// </summary>
        public int RowCount { get { return rows.Count; } }
        /// <summary>
        /// 指定行的列数量
        /// </summary>
        /// <param name="row">行号</param>
        /// <returns></returns>
        public int ColCount(int row)
        {
            if (row < 0 || row >= rows.Count) return 0;
            return rows[row].cells.Count;
        }
        /// <summary>
        /// 所有行中最大的列数
        /// </summary>
        public int MaxColCount
        {
            get
            {
                int maxCol = 0;
                foreach (VonCellItem item in rows)
                {
                    if (maxCol < item.cells.Count) maxCol = item.cells.Count;
                }
                return maxCol;
            }
        }
        public string this[int row, int col]
        {
            get
            {
                return rows[row].cells[col];
            }
        }
        public void Add(string[] values)
        {
            VonCellItem item = new VonCellItem();
            foreach (string s in values)
            {
                item.cells.Add(s);
            }
            rows.Add(item);
        }
        public bool ContainsListCollection => false;

        public IEnumerator GetEnumerator()
        {
            return rows.GetEnumerator();
        }

        public IList GetList()
        {
            return rows;
        }
    }
    public interface IVonSectionItemBase<T>
    {
        string key { get; set; }
        bool isArray { get; }
        T value { get; set; }
    }
    public class VonSectionItem<T> : IVonSectionItemBase<T> where T: class
    {
        public string key { get; set; }
        public bool isArray { get { return false; } }
        public T value { get; set; }
    }
    public class VonSectionArray : VonSectionItem<List<IVonSectionItemBase<object>>>
    {
        public bool isArray { get { return true; } }
        public VonSectionArray(List<object> arr = null)
        {
            if (arr == null) value = new List<object>();
            else value = arr;
        }
        public string key { get; set; }
        public List<object> value { get; private set; }
    }
    //public class VonSection
    //{
    //    public List<VonSectionItemBase> items = new List<VonSectionItemBase>();
    //    public VonSectionItemBase this[int index] { get { return items[index]; } set { items[index] = value; } }
    //    public VonSectionItemBase this[string key] {
    //        get
    //        {
    //            VonSectionItemBase item = items.FirstOrDefault(i => i.key.Equals(key, StringComparison.OrdinalIgnoreCase));
    //            return item == null ? default : item;
    //        }
    //        set
    //        {
    //            VonSectionItemBase item = items.FirstOrDefault(i => i.key.Equals(key, StringComparison.OrdinalIgnoreCase));
    //            if (item == null) items.Add(value);
    //            else
    //            {
    //                items.Remove(item);
    //                items.Add(value);
    //            }
    //        }
    //    }
    //    public T Value<T>(int index) { return (T)items[index].value; }
    //    public void Value<T>(int index, T value) { items[index].value = value; }
    //    public T Value<T>(string key)
    //    {
    //        VonSectionItem item = items.FirstOrDefault(i => i.key.Equals(key, StringComparison.OrdinalIgnoreCase));
    //        return item == null ? default : (T)item.value;
    //    }
    //    public void Value<T>(string key, T value)
    //    {
    //        VonSectionItem item = items.FirstOrDefault(i => i.key.Equals(key, StringComparison.OrdinalIgnoreCase));
    //        if (item == null) items.Add(new VonSectionItem() { key = key, value = value });
    //        else item.value = value;
    //    }
    //    public void Delete(string key)
    //    {
    //        VonSectionItem item = items.FirstOrDefault(i => i.key.Equals(key, StringComparison.OrdinalIgnoreCase));
    //        if (item == null) items.Remove(item);
    //    }
    //    public void Delete(int index)
    //    {
    //        items.RemoveAt(index);
    //    }
    //    public void Clear()
    //    {
    //        items.Clear();
    //    }
    //}
    public class VonFixedTable<T>
    {
        private string[] fields;
        private T[,] cells;
        public VonFixedTable(int ColCount, int RowCount)
        {
            fields = new string[ColCount];
            cells = new T[ColCount, RowCount];
        }
    }
}
